package com.cyc.basic.service.transaction;

import com.cyc.basic.test.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @Description: spring 编程时事务
 * @version 1.0
 * @author cyc
 * @date 2021/9/23 9:56
 */
@Service
public class SpringTransactionTest {

    @Autowired
    private TransactionTemplate transactionTemplate;

    public void save(User user) {
        queryData1();
        queryData2();
        transactionTemplate.execute(transactionStatus -> {
            addData1();
            updateData2();
            return Boolean.TRUE;
        });
    }

    private void updateData2() {

    }

    private void addData1() {

    }

    private void queryData2() {

    }

    private void queryData1() {

    }
}
